package com.itcast.arrays;

import com.itcast.Array.Student;

import java.util.Arrays;
import java.util.Comparator;

/*
    多条件排序的问题
        我们可以先第一条件, 如果为0则在比较第二条件,以此类推!!!!
 */
public class Test6 {

    public static void main(String[] args) {
        Student[] arr = {
                new Student("aaa", 18, 170, 65, 100),
                new Student("ccc", 17, 179, 55, 20),
                new Student("bbb", 17, 179, 55, 10),
                new Student("ddd", 17, 176, 50, 15),
                new Student("eee", 16, 180, 52, 90),
        };
        Arrays.sort(arr, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //比较年龄
                int result = o1.getAge() - o2.getAge();
               // result = result == 0 ? o1.getHeight() - o2.getHeight() : result;
                result = result == 0 ? o1.getWeight() - o2.getWeight() : result;
                result = result == 0 ? o1.getScore() - o2.getScore() : result;
                return result;
            }
        });

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}
